<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        img{
            max-width: 100%;
        }
    </style>
</head>
<body>
    
    <select name="" id="color_input">
        <option value="white">白色</option>
        <option value="black">黑色</option>
        <option value="silver">银色</option>
        <option value="blue">蓝色</option>
        <option value="red">红色</option>
    </select>
    <script>
        // 流程代码
        // const images={
        //     "white": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSW,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
        // "blue": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSB,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
        // "red": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX11,$PPMR,$WX00,$IBC00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
        // "silver": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSB,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
        // "black": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PBSB,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203"
        // }
        // const color_input=document.getElementById('color_input');
        // const imgEle=document.getElementById('car')
        // color_input.addEventListener('change',function(){
        //     // console.log(this.value);
        //     const current_color=this.value;
        //     imgEle.scr=images[curent_color];
        // })
          //面向对象思想 
        class TeslaBuy{
            constructor(){
                this.car()=null;
                this.colorInput()=null;
                this.images={
             "white": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSW,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
         "blue": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSB,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
         "red": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX11,$PPMR,$WX00,$IBC00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
         "silver": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PPSB,$WX00,$IBE00&view=SIDE&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203",
         "black": "https://static-assets.tesla.cn/configurator/compositor?&options=$MTX10,$PBSB,$WX00,$IBE00&view=FRONT34&model=mx&size=1920&bkba_opt=1&version=v0027d202107081203&crop=1300,600,300,230&version=v0027d202107081203"
         }

                // this组织属性和方法 作为对象的方法被调用 ，this指向对象本身
              this.init()
            }
            init(){
                this.car=document.getElementById('car')
                this.colorInput=document.getElementById('color_input')
                this.bindColorChangeEvent();
                
            }
            // 负责绑定改变车的颜色
            // 换车色事件添加
            bindColorChangeEvent(){
                this.colorInput.addEventListener('change',
                this.changeCarColor.bind(this))
                //  .bind产生一个新                .bind(this) bind 可以手动指定一个函数的 this指向 当前对象
                // 第一个参数this（对象）
            }
            changeCarColor(){

                console.log(this,'+++++++++++');
                const curent_color=this.colorInput.value;
                // const curent_color=this.value;
                // console.log(this.images)
                this.car.scr=this.images[curent_color]

            }
        }
        new TeslaBuy();
    </script>
</body>
</html>